﻿using AutoMapper;
using B.S.Material.Domain.BOM;
using B.S.Material.ErrorCode;
using B.S.Material.Read.Api.Applications.Command.MaterialsCommnad;
using MediatR;
using SqlSugar;

namespace B.S.Material.Read.Api.Applications.Handler.MaterialsHandler
{
    public class FTMaterialsHandler : IRequestHandler<FTMaterialsCommnad, ApiResult<List<Materials>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public FTMaterialsHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<List<Materials>>> Handle(FTMaterialsCommnad request, CancellationToken cancellationToken)
        {
            ApiResult<List<Materials>> result = new ApiResult<List<Materials>>();
            var list = await db.Queryable<Materials>().Where(x => x.IsDel == false && x.BOMID == request.BOMID).ToListAsync();
            result.data = list;
            result.Code = ApiEnum.显示成功;
            result.MAG = ApiEnum.显示成功.ToString();
            return await Task.FromResult(result);
        }
    }
}
